//
//  VVStack.m
//  SideDemo
//
//  Created by zsp on 16/5/13.
//  Copyright © 2016年 zsp. All rights reserved.
//

#import "VVStack.h"

@interface VVStack ()

@property(nonatomic, strong)NSMutableArray *numbers;

@end

@implementation VVStack
- (instancetype)init {
    if (self=[super init]) {
        _numbers=[NSMutableArray array];
    }
    return self;
}


- (void)push:(double)num {
    [self.numbers addObject:@(num)];
}
- (double)top {
    return [[self.numbers lastObject] doubleValue];
}

- (double)pop {
    
    if ([self count] == 0) {
        [NSException raise:@"VVStackPopEmptyException" format:@"Can not pop an empty stack."];
    }
    
    double popNumber=[self top];
    [self.numbers removeLastObject];
    return popNumber;
}

- (NSUInteger)count {
    return [self.numbers count];
}

@end
